server = require './server'
path = require 'path'
server.start()

# watch server script
serverWatcher = require('chokidar').watch '.', {ignored: /^(?:[\/\\]\.)|(?:.*\.(?:map)|(?:coffee(?:___jb_(bak|old)___)?))$/, persistent: true}
serverWatcher.on 'change', (filePath)->
  console.log "server file "+ filePath + " has been changed...."
  return if filePath == path.basename __filename
  console.log 'update server script, refresh require cache '+ filePath
#  require.cache http://nodejs.org/api/globals.html#globals_require_cache
  delete require.cache[path.resolve(filePath)]
  server.stop()
  server = require './server'
  server.start()
